package com.alibaba.seckill.service.impl;

import com.alibaba.seckill.exception.GlobalException;
import com.alibaba.seckill.pojo.Goods;
import com.alibaba.seckill.mapper.GoodsMapper;
import com.alibaba.seckill.service.IGoodsService;
import com.alibaba.seckill.vo.GoodsVo;
import com.alibaba.seckill.vo.RespBeanEnum;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 * @author 曹帅
 * @since 2021-11-18
 */
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements IGoodsService {
    /**
     * 获取商品相关信息
     * @return
     */
    @Override
    public List<GoodsVo> findGoodsVo() {
        List<GoodsVo> goodsVoList = baseMapper.findGoodsVo();
        if (goodsVoList.size() == 0) {
            throw new GlobalException(RespBeanEnum.NO_GOODS_INFO);
        }
        return goodsVoList;
    }

    /**
     * 查询商品相关信息
     * @param goodsId
     * @return
     */
    @Override
    public GoodsVo findGoodsVoByGoodsId(Long goodsId) {
        return baseMapper.findGoodsVoByGoodsId(goodsId);
    }
}
